package bird.queue;

import bird.queue.array_queue.ArrayQueue;
import bird.queue.array_queue.LoopQueue;
import bird.queue.linkedlist_queue.LinkedListQueue;

/**
 * @author sijunqiang
 * @data 2021/5/23 12:45
 * @description: 比较--数组队列和循环队列的时间复杂度分析和链表队列
 */
public class CompareLoopQueueAndArrayQueueAndLinkedListQueue {

    // 比较 使用不同的队列queue 进行计算qCount个数 的enqueue 和dequeue的耗时。
    public static double testQueue(Queue<Integer> queue, int qCount) {
        double start = System.nanoTime();
        for (int i = 0; i < qCount; i++)
            queue.enqueue(i);
        for (int i = 0; i < qCount; i++)
            queue.dequeue();
        double end = System.nanoTime();
        double time = (end - start) / 1000000000;
        return time;
    }


    public static void main(String[] args) {
        int qCount = 100000;

        //Test arrayQueue elapsed time
        ArrayQueue<Integer> arrayQueue = new ArrayQueue<>();
        double time = testQueue(arrayQueue, qCount);
        System.out.println("ArrayQueue: time= " + time + " s");

        //Test loopQueue elapsed time
        LoopQueue<Integer> loopQueue = new LoopQueue<>();
        double time2 = testQueue(loopQueue, qCount);
        System.out.println("LoopQueue: time= " + time2 + " s");

        //Test LinkedList elapsed time
        LinkedListQueue<Integer> linkedListQueue=new LinkedListQueue<>();
        double time3 = testQueue(linkedListQueue, qCount);
        System.out.println("LinkedList: time= " + time3 + " s");
    }
}
